/*
 * @Author: OreoWang
 * @Email: ihc523@163.com
 * @Date: 2020-06-01 12:05:23
 * @LastEditors: OreoWang
 * @LastEditTime: 2022-08-10 16:32:12
 * @Description: 数据模型定义
 */


import { _decorator, Component } from "cc";
import { logger } from "./ViewLogger";
import { ViewTool } from "./ViewTool";
import ViewNode from "./ViewNode";
import ViewController from "./ViewController";
import IViewRender from "./IViewRender";


type ViewObject = {
    [propName: string]: any;
}
type ViewArray = Array<any>;

//组件化数据模型
export class ViewData{
    [propName: string]: string | boolean | number | ViewArray | ViewObject;
}

//组件化数据模型
export default class ViewModel {
    vm: Vue|null = null;
    
    constructor(
        public controller: ViewController, 
        public view: ViewNode, 
        public data: ViewData)
    {
        if(!view || !data){
            logger.error("无效的参数: ", view, data);
            return;
        }
        this.create();
    }

    create(){
        this.vm = ViewTool.createViewModel(()=>{
            return this.compile(this.controller, this.view, this.data);
        });
    }
    destroy(){
        ViewTool.destroy(this.vm);
    }

    /**
     * 子类重写，实现模型绑定
     * @param controller 
     * @param view 
     * @param data 
     * @returns 
     */
    compile(controller: ViewController, view: ViewNode, data: ViewData): IViewRender{
        return {
            data: data,
            template: {},
            computed: {},
            watch: {}
        }
    }
}